package com.warren.config;


import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.TopLevelClass;

import java.util.List;

public class LombokPlugin extends PluginAdapter {

    FullyQualifiedJavaType mapperType = new FullyQualifiedJavaType("org.springframework.stereotype.Repository");

    @Override
    public boolean validate(List<String> warnings) {
        return true;
    }

    @Override
    public boolean modelGetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
        // model类阻止getter生成
        return false;
    }

    @Override
    public boolean modelSetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
        // model类阻止setter生成
        return false;
    }

//    @Override
//    public boolean clientGenerated(Interface interfaze, IntrospectedTable introspectedTable) {
//        // 给mapper.java增加注解
//        interfaze.addAnnotation("@Repository");
//        interfaze.addImportedType(mapperType);
//        return super.clientGenerated(interfaze, introspectedTable);
//    }

    @Override
    public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass,
                                                 IntrospectedTable introspectedTable) {
        // model类增加@Data注解
        topLevelClass.addAnnotation("@Data");
        topLevelClass.addImportedType("lombok.Data");
        return true;
    }

}